package tsing.javase.optiona;



import tsing.javase.common.bean.Person;

import java.util.Optional;

/**
 * @Author Tsing/吴清平
 * @Date 2022/12/27 17:01
 */
public class OptionalDemo {
    public static void main(String[] args) {


        try {
//            Optional<?> person = getObject(Class.forName("org.tsing.javase.common.bean.Person"));
            Optional<?> person = getObject(Person.class);
            Person person1 = Person.class.newInstance();
            System.out.println(person == null);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }


    }


    public static <T> Optional<T> getObject(Class<T>e) throws IllegalAccessException, InstantiationException {
       T p =  e.newInstance();
        return Optional.ofNullable(p);
    }



}
